<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use common\models\Category;
use yii\helpers\ArrayHelper;
use backend\components\Helper;
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 18-1-12
 * Time: 下午3:28
 */?>
<div class="col-md-12">
<h1><?= Html::encode('文章管理') ?></h1>

<p>
    <?= Html::a(Yii::t('app', '新建文章'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
</div>
<?php
    echo $this->render('/layouts/menu');
?>

<div class="col-md-10 container-left">
    <?php Pjax::begin(); ?>    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            //        'id',
            [
                'attribute'=>'type',
                'value'=> function($data){
                    $type  = Category::find()->all();
                    $ds = ArrayHelper::map($type,'id', 'name');
                    return $data['type'];
                },
            ],
            'title',
            [
                'attribute'=>'content',
                'format'=>'raw',
                'value'=> function($data){
                    $content = $data['content'];
                    return Helper::truncate_utf8_string($content,20);
                },
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>
